package org.jeecg.modules.role.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.ServiceNameConstants;
import org.jeecg.modules.role.entity.SysRole;
import org.jeecg.modules.role.fallback.RoleFallback;
import org.jeecg.modules.user.entity.SysUser;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Component
@FeignClient(contextId = "SysRoleApi", value = ServiceNameConstants.SERVICE_SYSTEM, path = ServiceNameConstants.PATH_SYS_ROLE, fallback = RoleFallback.class)
@ConditionalOnMissingClass("org.jeecg.modules.system.controller.SysRoleController")
public interface RoleApi {

    @PostMapping(value = "save")
    @ApiOperation(value = "保存")
    public Result<Boolean> save(@RequestBody SysRole role);


    @RequestMapping(value = "/queryById", method = RequestMethod.GET)
    @ApiOperation(value = "查询角色信息")
    public Result<SysRole> queryById(@RequestParam(name = "id", required = true) String id);

    @GetMapping("getByOrgAndDeptIdList")
    @ApiOperation(value = "根据组织id部门列表获取角色列表")
    Result<IPage<SysRole>> getByOrgAndDeptIdList(@RequestParam String organizationId, @RequestParam List<String> departList,
                                                 String roleName, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize);

    @GetMapping("userList")
    @ApiOperation(value = "获取角色下用户列表")
    Result<IPage<SysUser>> listUserIdByRoleId(@RequestParam String roleId, @RequestParam(name = "username", required = false) String username,
                                              @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                              @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize);

    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除角色")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id);


    @GetMapping(value = "permissionList")
    @ApiOperation(value = "组织的菜单列表")
    public Result<Map<String, Object>> getPermissionList(@RequestParam String orgId);
}


